package DHBW.Convert;

public class CharConverter {

	public static String byte2HexStr(int input) {
    	return "0x"+(input/16)+(input % 16);
    }
    
    public static byte[] hex2Dezimal(byte buffer) {
    	byte[] result = new byte[3];
    	
    	result[0] = (byte) (0x30 + buffer/100);
    	result[1] = (byte) (0x30 + (buffer-result[1])/10);        	
    	result[2] = (byte) (0x30 + buffer % 10);
    	
    	return result;
    }
    
    public static char[] threeDigit2Char(int input) {
    	char[] result = new char[3];
    	
    	result[0] = (char) (0x30 + input/100);
    	result[1] = (char) (0x30 + (input-result[1])/10);        	
    	result[2] = (char) (0x30 + input % 10);
    	
    	return result;
    }
    
    public static byte[] toChat(byte[] data, int laenge) {
    	byte[] result = new byte[3*laenge+7];
    	byte[] temp = hex2Dezimal(data[0]);
    	int counter = 7;
    	
    	result[0] = (byte)('I');
    	result[1] = (byte)('D');
    	result[2] = temp[0];
    	result[3] = temp[1];
    	result[4] = temp[2];
    	result[5] = (byte)(':');
    	result[6] = (byte)(' ');
    	
    	for (int i=1;i<=laenge;i++) {
    		temp = hex2Dezimal(data[i]);
    		result[counter] = temp[0];
    		result[counter+1] = temp[1];
    		result[counter+2] = temp[2];
    		counter = counter + 3;
    	}
    	       	
    	return result;
    	
    }
}
